<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>美食社区 - 首页</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.1/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.2/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        .post-meta .author {
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .post-meta .author i {
            color: #6c757d;
        }
    </style>
</head>

<body>
    <!-- 导航栏 -->
    <nav th:replace="~{common/header :: header}"></nav>

    <!-- Banner轮播图 -->
    <div id="mainCarousel" class="carousel slide" data-bs-ride="carousel">
        <div class="carousel-indicators">
            <button th:each="post,iterStat : ${hotPosts}" type="button" data-bs-target="#mainCarousel"
                th:data-bs-slide-to="${iterStat.index}" th:class="${iterStat.first}? 'active'">
            </button>
        </div>
        <div class="carousel-inner">
            <div th:each="post,iterStat : ${hotPosts}"
                th:class="${iterStat.first}? 'carousel-item active' : 'carousel-item'">
                <div class="carousel-img-container">
                    <img th:src="${post.firstImage}" class="d-block w-100" th:alt="${post.title}">
                    <div class="carousel-caption">
                        <h3 th:text="${post.title}"></h3>
                        <p th:text="${post.summary}"></p>
                    </div>
                </div>
            </div>
        </div>
        <button class="carousel-control-prev" type="button" data-bs-target="#mainCarousel" data-bs-slide="prev">
            <span class="carousel-control-prev-icon"></span>
        </button>
        <button class="carousel-control-next" type="button" data-bs-target="#mainCarousel" data-bs-slide="next">
            <span class="carousel-control-next-icon"></span>
        </button>
    </div>

    <!-- 美食分类展示 -->
    <div class="container mt-5">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2 class="section-title">美食分类</h2>
            <a href="/category" class="btn btn-outline-primary">查看全部</a>
        </div>
        <div class="row g-4">
            <div class="col-md-3 col-sm-6" th:each="category : ${categories}">
                <a th:href="@{/posts(category=${category.name})}" class="text-decoration-none">
                    <div class="category-card">
                        <div class="category-icon">
                            <i class="fas fa-utensils"></i>
                        </div>
                        <h3 class="category-title" th:text="${category.name}"></h3>
                        <p class="category-desc" th:text="${category.description}"></p>
                        <span class="category-count"
                            th:text="${category.postCount != null ? category.postCount + ' 篇文章' : '0 篇文章'}"></span>
                    </div>
                </a>
            </div>
        </div>
    </div>

    <!-- 热门餐厅 -->
    <div class="container mt-5">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2 class="section-title">热门餐厅</h2>
            <a href="/restaurant" class="btn btn-outline-primary">
                查看更多 <i class="fas fa-arrow-right"></i>
            </a>
        </div>
        <div class="row g-4">
            <div class="col-md-6" th:each="restaurant : ${hotRestaurants}">
                <div class="restaurant-card">
                    <div class="row g-0">
                        <div class="col-md-4">
                            <div class="restaurant-img">
                                <img th:src="${restaurant.image}" class="img-fluid rounded" th:alt="${restaurant.name}"
                                    loading="lazy">
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="card-body">
                                <h5 class="card-title" th:text="${restaurant.name}"></h5>
                                <div class="restaurant-rating">
                                    <span class="rating-score" th:text="${restaurant.rating}">4.8</span>
                                    <div class="rating-stars">
                                        <i class="fas fa-star"></i>
                                        <i class="fas fa-star"></i>
                                        <i class="fas fa-star"></i>
                                        <i class="fas fa-star"></i>
                                        <i class="fas fa-star-half-alt"></i>
                                    </div>
                                    <span class="review-count"
                                        th:text="${restaurant.reviewCount != null ? restaurant.reviewCount + '条评价' : '0条评价'}">评价数量</span>
                                </div>
                                <p class="restaurant-cuisine" th:text="${restaurant.cuisineType}">川菜</p>
                                <p class="restaurant-address">
                                    <i class="fas fa-map-marker-alt"></i>
                                    <span th:text="${restaurant.address}"></span>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 美食日记 -->
    <div class="container-fluid">
        <div class="d-flex justify-content-between align-items-center px-3 mb-3">
            <h2 class="section-title">美食日记</h2>
            <a href="/posts" class="btn btn-link text-decoration-none">
                查看更多 <i class="fas fa-angle-right"></i>
            </a>
        </div>
        <div class="masonry-grid">
            <div th:each="post : ${morePosts}" class="masonry-item">
                <div class="post-card">
                    <div class="post-image">
                        <img th:src="${post.firstImage}" th:alt="${post.title}" loading="lazy">
                    </div>
                    <div class="post-info">
                        <h3 class="post-title" th:text="${post.title}"></h3>
                        <p class="post-summary" th:text="${post.summary}"></p>
                        <div class="post-meta">
                            <span class="author">
                                <i class="fas fa-user me-1"></i>
                                <span th:text="${post.authorName}"></span>
                            </span>
                            <span class="stats">
                                <i class="fas fa-eye"></i> <span th:text="${post.views}"></span>
                                <i class="fas fa-heart"></i> <span th:text="${post.likes}"></span>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="load-more-container">
            <button id="loadMore" class="btn">
                加载更多
            </button>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="footer mt-5 py-4 bg-white">
        <div class="container text-center">
            <p class="text-muted mb-0">© 2024 美食社区 - 分享美食，分享生活</p>
        </div>
    </footer>

    <!-- Bootstrap Bundle with Popper -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.1/js/bootstrap.bundle.min.js"></script>
    <!-- jQuery -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <!-- 退出登录脚本 -->
    <script th:replace="~{common/header :: logout-script}"></script>
    <script th:src="@{/js/index.js}"></script>
</body>

</html>